"""
78子集问题测试数据生成器
根据md文档中的示例和约束条件生成测试用例
"""
import random

def generate_expected_result(nums):
    """
    根据输入数组生成期望的子集结果
    使用位运算方法生成所有子集
    """
    result = []
    n = len(nums)
    
    # 遍历所有可能的子集状态 (0 到 2^n - 1)
    for i in range(2 ** n):
        subset = []
        for j in range(n):
            # 检查第j位是否为1
            if i & (1 << j):
                subset.append(nums[j])
        result.append(subset)
    
    return result

def generate_test_cases():
    """生成测试用例"""
    test_cases = []
    
    # 基础测试用例 - 来自md文档示例
    test_cases.append({
        "name": "示例1 - 基础三元素数组",
        "description": "来自LeetCode示例1",
        "input": [1, 2, 3],
        "expected": [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
    })
    
    test_cases.append({
        "name": "示例2 - 单元素数组", 
        "description": "来自LeetCode示例2",
        "input": [0],
        "expected": [[], [0]]
    })
    
    # 边界测试用例
    test_cases.append({
        "name": "最小数组",
        "description": "只有一个元素的最小测试",
        "input": [5],
        "expected": generate_expected_result([5])
    })
    
    test_cases.append({
        "name": "负数测试",
        "description": "包含负数的数组",
        "input": [-1, 0, 1],
        "expected": generate_expected_result([-1, 0, 1])
    })
    
    test_cases.append({
        "name": "四元素数组",
        "description": "测试四个元素的所有子集",
        "input": [1, 2, 3, 4],
        "expected": generate_expected_result([1, 2, 3, 4])
    })
    
    # 更大的测试用例
    test_cases.append({
        "name": "五元素数组",
        "description": "测试五个元素，共32个子集",
        "input": [1, 2, 3, 4, 5],
        "expected": generate_expected_result([1, 2, 3, 4, 5])
    })
    
    # 随机测试用例
    for i in range(3):
        size = random.randint(2, 6)
        nums = random.sample(range(-10, 11), size)
        test_cases.append({
            "name": f"随机测试{i+1}",
            "description": f"随机生成的{size}元素数组",
            "input": nums,
            "expected": generate_expected_result(nums)
        })
    
    # 边界值测试
    test_cases.append({
        "name": "最大边界值",
        "description": "包含最大最小值的测试",
        "input": [-10, -5, 0, 5, 10],
        "expected": generate_expected_result([-10, -5, 0, 5, 10])
    })
    
    return test_cases

def print_test_cases():
    """打印所有测试用例"""
    test_cases = generate_test_cases()
    
    print("=" * 60)
    print("78子集问题 - 测试数据")
    print("=" * 60)
    
    for i, case in enumerate(test_cases, 1):
        print(f"\n测试用例 {i}: {case['name']}")
        print(f"描述: {case['description']}")
        print(f"输入: {case['input']}")
        print(f"期望输出: {case['expected']}")
        print(f"子集数量: {len(case['expected'])}")
        print("-" * 40)
    
    return test_cases

if __name__ == "__main__":
    print_test_cases()